<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2019/1/12
 * Time: 10:38
 */

namespace app\enterprise\service;


class Book
{
    public $url = '';
    function __construct()
    {
        $this->url = config('setting.base_url');
    }
    /**
     * 获取成交率信息
     * @param $token
     * @return null
     */
    public function getUserRateNum($token,$rate){
        $url=$this->url."/user/rate";
        $params = $rate;
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 用户列表信息
     * @param $token
     * @return null
     */
    public function getUserList($token,$type){
        $url=$this->url."/user/list";
        $params = ['type'=>$type];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取用户信息
     * @param $token
     * @param $id
     * @return null
     */
    public function getUserById($token,$id){
        $url=$this->url."/user/".$id;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 更新用户信息
     * @param $token
     * @param $id
     * @return null
     */
    public function updateUser($token,$info){
        $url = $this->url."/user/update";
        $params = $info;
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 添加用户标签
     * @param $token
     * @param $id
     * @return null
     */
    public function addUserLabel($token,$user_id,$data){
        $url=$this->url."/user/add_label";
        $data['user_id']=$user_id;
        $params = $data;
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 更新标签信息
     * @param $token
     * @param $id
     * @return null
     */
    public function updateLabel($token,$data){
        $url=$this->url."/user/label/update";
        $params = $data;
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 删除标签信息
     * @param $token
     * @param $id
     * @return null
     */
    public function deleteLabel($token,$id){
        $url=$this->url."/user/label/delete/".$id;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 更新标签信息
     * @param $token
     * @param $id
     * @return null
     */
    public function addLabel($token,$data){
        $url=$this->url."/user/label/add";
        $params = $data;
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 获取用户标签列表
     * @param $token
     * @return null
     */
    public function getLabelList($token){
        $url=$this->url."/user/label/list";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取标签用户
     * @param $token
     * @return null
     */
    public function getUserByLabel($token,$id){
        $url=$this->url."/user/label/".$id;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 获取用户标签
     * @param $token
     * @return null
     */
    public function getLabelByUser($token,$uid){
        $url=$this->url."/user/label/user/".$uid;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取跟进记录列表
     * @param $token
     * @return null
     */
    public function getFollowList($token,$uid,$page){
        $url=$this->url."/follow/data";
        $params = [$uid,$page];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取跟进记录
     * @param $token
     * @return null
     */
    public function getFollowData($token,$id,$time){
        $url=$this->url."/follow/list";
        $params = [$id,$time];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取用户行为统计
     * @param $token
     * @return null
     */
    public function getBehaviorData($token,$uid){
        $url=$this->url."/behavior/data/".$uid;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 用户活跃度统计
     * @param $token
     * @return null
     */
    public function getActiveData($token,$uid,$time){
        $url=$this->url."/behavior/active";
        $params = [$uid,$time];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取用户反馈统计
     * @param $token
     * @return null
     */
    public function getInteractionData($token,$uid){
        $url=$this->url."/behavior/interactive/".$uid;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

}